package businessCommonQuery

import (
	"fmt"
	"grpc.getaway.adminspro.padmins.com/pkg/libs/utils"
	"strings"
)

func ListFormat(list map[string]map[string]string, row map[string]interface{}) {
	for key, item := range list {
		if val, ok := row[key]; ok {
			row[key+"_text"] = ""
			values := []interface{}{}
			for _, value := range strings.Split(fmt.Sprintf("%v", val), ",") {
				values = append(values, value)
			}

			for k, v := range item {
				if utils.InArray(k, values) {
					row[key+"_text"] = fmt.Sprintf("%s%s,", row[key+"_text"], v)
				}
			}

			if row[key+"_text"] != "" {
				row[key+"_text"] = strings.Trim(row[key+"_text"].(string), ",")
			}
		}
	}
}
